package br.com.orion.sga.model.dao;


import javax.persistence.NoResultException;
import javax.persistence.Query;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import br.com.orion.sga.exception.DaoException;
import br.com.orion.sga.model.entities.Responsavel;

@Transactional
@Repository("responsavelDao")
public class ResponsavelDao extends GenericDao<Responsavel, Long> {
	
	public Logger logger = Logger.getLogger("sga");
	
	/**
	 * get Responsible by CPF
	 * @param cpf
	 * @return
	 */
	public Responsavel getByCPF(String cpf) throws DaoException{
		
		logger.info("search by CPF");
		logger.debug("debug");
		
		Query q = entityManager.createQuery("from Responsavel r WHERE r.cpf = :cpf");
		q.setParameter("cpf", cpf);
		try {
			return (Responsavel) q.getSingleResult();
		} catch (NoResultException e) {
			throw new DaoException("Nenhum registro foi localizado!");
		}
	}

}
